﻿using System;
using System.Reflection;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode;

namespace HYCodeBase.SqlUtility.ORMSuit
{
	internal class EntityAutoMappingHandler
	{
		internal EntityAutoMappingHandler()
		{
			this.PrepareMethod();
		}

		private void PrepareMethod()
		{
			this.m_useMethod = this.useType.GetMethod("Class");
			this.m_useSimpleUtiltiyMehtod = typeof(EntityAutoMappingUtility).GetMethod("EntityMapping", BindingFlags.Static | BindingFlags.NonPublic);
		}

		internal void RegiesType(Type input)
		{
			MethodInfo methodInfo = this.m_useMethod.MakeGenericMethod(new Type[]
			{
				input
			});
			object obj = this.m_useSimpleUtiltiyMehtod.MakeGenericMethod(new Type[]
			{
				input
			}).Invoke(null, null);
			methodInfo.Invoke(this.m_useModelMapper, new object[]
			{
				obj
			});
		}

		internal HbmMapping GetHbmMapping()
		{
			return this.m_useModelMapper.CompileMappingForAllExplicitlyAddedEntities();
		}

		private const string m_strUseMethodName = "Class";

		private const string m_strUseSimpleMethodName = "EntityMapping";

		private ModelMapper m_useModelMapper = new ModelMapper(new UseEntityModelInspector());

		private Type useType = typeof(ModelMapper);

		private MethodInfo m_useMethod;

		private MethodInfo m_useSimpleUtiltiyMehtod;
	}
}
